package wn.lizzy.thread.ball;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JPanel;

/**
 * 面板具有长宽属性，以及增加小球，画球的方法
 * @author cuilijian
 *
 */
@SuppressWarnings("serial")
public class BallComponent extends JPanel {

	private static final int DEFAULT_WIDTH = 450;
	private static final int DEFAULT_HEIGHT = 450;
	
	private List<Ball> balls  = new ArrayList<>();
	
	public void add(Ball b){
		balls.add(b);
	}
	
	public void paintComponent(Graphics g){
		super.paintComponent(g);
		Graphics2D g2 = (Graphics2D) g;
		for(Ball b : balls){
			g2.fill(b.getShape());
		}
	}
	
	public Dimension getPreferredSize(){
		return new Dimension(DEFAULT_WIDTH, DEFAULT_HEIGHT);
	}
}
